package protocal;

import protocal.DataPackage.MessageType;


/*when DataPacket.MessageType is LOGIN
 * require : fromeName:username,toName:\,MessageType:LOGIN
 * DataPacket.MessageType is MESSAGE
 * require : fromeName:username,toName:username or \,MessageType:MESSAGE, messageData:messageData
 * 	DataPacket.MessageType is SHAKE
 * require : fromeName:username,toName:username(not \),MessageType:SHAKE, 	
 * DataPacket.MessageType is LOGOUT
 * require:  fromeName:username,toName:\,MessageType:LOGOUT
 * 
 * DataPacket.MessageType cannot be LIST
 * 
 */


public class DataPackageFilter implements Filter {
	
	

	@Override
	public boolean filter(DataPackage dataPackage) {
		if (dataPackage.getFromeName()==null||dataPackage.getToName().equals("")) {
			return false;
		}
		if (dataPackage.getToName()==null||dataPackage.getToName().equals("")) {
			return false;
		}
		if (dataPackage.getMessageType()==null) {
			return false;
		}
		if (dataPackage.getMessageType()==MessageType.LOGIN||dataPackage.getMessageType()==MessageType.LOGOUT) {
			if (!dataPackage.getToName().equals("\\")) {
				return false;
			}
		}
		if (dataPackage.getMessageType()==MessageType.MESSAGE) {
			if (dataPackage.getMessageData()==null||dataPackage.getMessageData().equals("")) {
				return false;
			}
		}
//		if (dataPackage.getMessageType()==MessageType.SHAKE) {
//			if (dataPackage.getToName().equals("\\")) {
//				return false;
//			}
//		}
		if (dataPackage.getMessageType()==MessageType.LIST) {
			return false;
		}
		
		return true;
	}

}
